package cqrtplm.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.QueryPartService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

import java.math.BigInteger;

@Slf4j
@CustomListener(category = "润通", description = "根据图样代号自动收集物料码")
public class RTAutoCollectPartListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) {
        String workFlowContainerId = execution.getProcessInstanceBusinessKey();
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = execution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }
        QueryPartService workFlowProcessService = SpringUtil.getBean(QueryPartService.class);
        String finalWorkFlowContainerId = workFlowContainerId;
        workFlowProcessService.autoCollectPart(new BigInteger(finalWorkFlowContainerId));
    }

}

